/**
 * 
 */
package com.cnhaimei.vod.logic;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;

import com.cnhaimei.vod.R;
import com.cnhaimei.vod.util.Const;
import com.cnhaimei.vod.util.Util;

/**
 * 单机版首页
 * 
 * @author hw <br>
 * @date 2013-5-24
 * 
 */
public class StandAloneHomeActivity extends VODActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.v8_standalone_home);

		setClickable( R.id.song, R.id.singer, R.id.barsong, R.id.film, R.id.favorites, R.id.hotrank );
		

//		View home = findViewById(R.id.home);
//		home.setBackgroundResource(R.drawable.home_active);

//		DisplayMetrics dm = getResources().getDisplayMetrics();
//		int wPix = dm.widthPixels;
//		int hPix = dm.heightPixels;

//		float w = dm.widthPixels / dm.xdpi;
//		float h = dm.heightPixels / dm.ydpi;
//		double inch = Math.sqrt(h * h + w * w);
		
//		Log.e("size:", "w:" + dm.widthPixels + " h:" + dm.heightPixels + "density:" + dm.density);
//		
//		Log.e("size1:", "w:" + w + " h:" + h + "inch:" + inch);
	}

	@Override
	public void onClick(View v) {
		int id = v.getId();
		switch (id) {
		case R.id.song:
			startActivity(Const.Action.ShowAllSongs);
			break;
		case R.id.singer:
			startActivity(Const.Action.showAllSingers);
			break;
		case R.id.barsong:
			startActivity(Const.Action.showBarSongs);
			break;
		case R.id.film:
			startActivity(Const.Action.showFilms);
			break;
		case R.id.favorites:
			startActivity(Const.Action.showFavorites);
			break;
		case R.id.hotrank:
			startActivity(Const.Action.showHotrank);
			break;
		case R.id.home:
			break;
		default:
			super.onClick(v); // need parent
			break;
		}
	}
	
	protected void onClickHome() {
//		finish();
		//empty 
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		switch (keyCode) {
		case KeyEvent.KEYCODE_BACK:
//			if (Util.TEST || Util.DEMO) {
//				setResult(RESULT_OK);
//			}
//				finish();
			confirmFinish();
			break;
		default:
			return super.onKeyDown(keyCode, event);
		}
		return true;
	}
	
	private void confirmFinish() {
		AlertDialog mAlertDialog = new AlertDialog.Builder(this).create();
		mAlertDialog.setIcon(android.R.drawable.ic_dialog_alert);
		mAlertDialog.setTitle(R.string.confirm_exit_home_title);
		mAlertDialog.setMessage(getString(R.string.confirm_exit_home));
		mAlertDialog.setButton(getString(R.string.yes),
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						finish();
					}
				});
		mAlertDialog.setButton2(getString(R.string.no),
				(DialogInterface.OnClickListener) null);
		mAlertDialog.show();
	}

}
